home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / scnsrv.zip / SCANSERV.C < prev    next >
Text File  |  1992-10-23  |  5KB  |  272 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <fcntl.h>
  5. #include <io.h>
  6. #include <conio.h>
  7. #include <dir.h>
  8. #include <share.h>
  9. #include <errno.h>
  10. #include <sys\stat.h>
  11. #include <dos.h>
  12. #include "version.h"
  13.  
  14. #pragma hdrstop
  15.  
  16. #include "newnov.h"
  17.  
  18. #define DEBUG 0
  19.  
  20. // --------------------------------------------------------------------------
  21. // main()
  22. //
  23. // --------------------------------------------------------------------------
  24.  
  25. struct NovellFileInfo nfi;
  26.  
  27. void
  28. PrintDOSdate(unsigned long t, char *str)
  29. {
  30.     struct ftime *ftp = (struct ftime *) &t;
  31. #define ft (*ftp)
  32.     t =
  33.     LongSwap(t);
  34. //    printf("File time: %u:%u:%u ",
  35. //         ft.ft_hour, ft.ft_min,
  36. //         ft.ft_tsec * 2);
  37.     cprintf( "%s%02.2u-%02.2u-%04.4u", str,
  38.          ft.ft_month,  ft.ft_day, ft.ft_year+1980);
  39.  
  40. }
  41.  
  42. int                 // J  F   M   A   M   J   J   A   S   O   N   D
  43. julian_table[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30 };
  44.  
  45. int
  46. julian(int year, int month, int day)
  47. {
  48.     return (day-1 + julian_table[month-1] + (year-1980)*365 );
  49. }
  50.  
  51.  
  52. int
  53. julianDOSdate(unsigned long t)
  54. {
  55.     struct ftime *ftp = (struct ftime *) &t;
  56.     t =
  57.     LongSwap(t);
  58.     return julian(ft.ft_year+1980, ft.ft_month,  ft.ft_day);
  59.  
  60. }
  61.  
  62. struct date today;
  63. int today_julian;
  64.  
  65. int
  66. scanit(char *path)
  67. {
  68.     int seqnum, res;
  69.     int pathendindex;
  70.     struct ScanDirInfoReply *dip;
  71.  
  72.     char *newpath;
  73.  
  74.     // Allocate a new path with enough room for catting an 8.3 name
  75.     //        and a backslash.
  76.     //    then check mem allocation
  77.  
  78.     pathendindex = strlen(path);
  79.  
  80.     // protect against creating a volname:path string > 254 chars.
  81.  
  82.     if (pathendindex > 254 - 14)
  83.         return 0;
  84.  
  85.     // Construct new path and request structs
  86.     newpath = malloc(pathendindex + 14);
  87.     dip     = malloc(sizeof(*dip));
  88.  
  89.     if (!newpath || !dip) {
  90.         cprintf("Out of memory");
  91.         exit(1);
  92.     }
  93.  
  94.     // announce the current dir, don't wrap the 80-column display!
  95.  
  96.     putch('\r');
  97.     clreol();
  98.     if (pathendindex > (80-16))
  99.         cprintf("Scanning: ... %s", &(path[pathendindex-(80-16)]));
  100.     else
  101.         cprintf("Scanning: %s", path);
  102.  
  103.     // create search path string for netware call
  104.  
  105.     strcpy(newpath, path);
  106.     strcat(newpath, "\\*");
  107.  
  108.     // scan all files in current directory
  109.  
  110.     seqnum = -1;
  111.  
  112.     while (1)
  113.     {
  114.         res = GetFileInfo(newpath, &nfi, seqnum);
  115.         seqnum = nfi.seqnum;
  116.  
  117.         switch (res)
  118.         {
  119.             case 0:
  120.                 printf("%lu\t%u\t%u\t%u\t%u\n",
  121.                     LongSwap(nfi.fileSize),
  122.                     today_julian - julianDOSdate(nfi.updateTime),
  123.                     today_julian - julianDOSdate(nfi.archiveTime),
  124.                     today_julian - julianDOSdate(nfi.creationDate),
  125.                     today_julian - julianDOSdate(nfi.accessDate));
  126.  
  127.                 if (
  128.                     today_julian - julianDOSdate(nfi.updateTime) < 0 ||
  129.                     today_julian - julianDOSdate(nfi.archiveTime) < 0 ||
  130.                     today_julian - julianDOSdate(nfi.creationDate) < 0 ||
  131.                     today_julian - julianDOSdate(nfi.accessDate) < 0
  132.                     )
  133.                 {
  134.                     putch('\r');
  135.                     clreol();
  136.                     cprintf("Date Anomaly on file: %s\\%s\r\n", path, nfi.filename);
  137.  
  138.                     PrintDOSdate(nfi.updateTime, "Update: ");
  139.                     PrintDOSdate(nfi.archiveTime, " Archive: ");
  140.                     PrintDOSdate(nfi.creationDate, " Create: ");
  141.                     PrintDOSdate(nfi.accessDate, " Access: ");
  142.                     cprintf("\r\n");
  143.  
  144.                 }
  145.  
  146.                 break;
  147.  
  148.             case 0xFF:    // no more files.
  149.                 res = 0;
  150.                 goto endloop;
  151.  
  152.             default:
  153.                 cprintf("Error %d during Get File Info on %s\n", res, path);
  154.                 exit(1);
  155.         }
  156.  
  157.     }
  158. endloop:
  159.  
  160.     // Done scanning files. Now scan for directories and recurse.
  161.     pathendindex++;
  162.  
  163.     dip->subdirNumber = -1;
  164.  
  165.     while (!res)
  166.     {
  167.         res = GetDirInfo(newpath, dip);
  168.  
  169.         if (!res)
  170.         {
  171.             newpath[pathendindex] = '\0';
  172.             strcat(newpath, dip->filename);
  173.  
  174.             scanit(newpath);
  175.  
  176.             newpath[pathendindex] = '\0';
  177.             strcat(newpath, "*");
  178.         }
  179.  
  180.         else
  181.         if (res != 0x9C)
  182.         {
  183.             cprintf("Error %d during Get Dir Info on %s\n", res, path);
  184.             exit(1);
  185.         }
  186.         else
  187.         {
  188.             res = 0;
  189.             break;
  190.         }
  191.     }
  192.     free(newpath); free(dip);
  193.  
  194.     return (res == 0xff ? 0 : res);
  195. }
  196.  
  197. int
  198. scanServer(char *servername, int serverConnIndex)
  199. {
  200.     char volName[20];
  201.     int volIndex;
  202.     int res = 0;
  203.  
  204.     cprintf("\r\nScanning server %s\r\n", servername);
  205.  
  206.     // Loop thru all volumes on a server, and scan them....
  207.  
  208.     for (volIndex = 0; !res && (volIndex < 32); volIndex++)
  209.     {
  210.         if (!GetVolumeName(volName, volIndex))
  211.         {
  212.             strcat(volName, ":");
  213.  
  214.             // Put out a marker to delineate a new volume scan
  215.  
  216.             printf("---------------------- S%d V%d -------------------------\n",
  217.                 serverConnIndex, volIndex);
  218.  
  219.             // scan the volume.
  220.             res = scanit(volName);
  221.         }
  222.  
  223.     }
  224.  
  225.     return res;
  226. }
  227.  
  228. int
  229. main(int argc, char *argv[])
  230. {
  231.     int res = 0;
  232.     int serverConnIndex = 0;
  233.     int saveConn;
  234.  
  235.     char servername[50];
  236.  
  237.     // Init julian date table and today's julian date.
  238.  
  239.     {
  240.         int i;
  241.         for (i=1; i<12; i++)
  242.             julian_table[i] += julian_table[i-1];
  243.     }
  244.  
  245.     getdate(&today);
  246.  
  247.     today_julian = julian(today.da_year, today.da_mon, today.da_day);
  248.  
  249.  
  250.     // special option to allow a path to be spec'd on the command line
  251.     //        for scanning...
  252.     if (argc > 1)
  253.     {
  254.         return scanit(argv[1]);
  255.     }
  256.  
  257.     // Scan server table, when one is found, scan it.
  258.  
  259.     while (!res && !GetNextServer(servername, &serverConnIndex))
  260.     {
  261.         saveConn = GetPreferredConnectionID();
  262.  
  263.         SetPreferredConnectionID(serverConnIndex);
  264.  
  265.         res = scanServer(servername, serverConnIndex);
  266.  
  267.         SetPreferredConnectionID(saveConn);
  268.     }
  269.  
  270.     return res;
  271. }
  272.